#define  _CRT_SECURE_NO_WARNINGS


#include<stdio.h>

int main()
{
	int n = 0, arr[1000] = { 0 }, i = 0, x = 0, y = 0, m = 0, temp = 0, j = 0, k = 0, a = 0;
	scanf("%d %d", &n, &m);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
	}
	for (i = 0; i < m; i++)
	{
		scanf("%d %d", &x, &y);
		if (x != y)
		{
			temp = arr[x - 1];
			arr[x - 1] = arr[y - 1];
			arr[y - 1] = temp;
		}
	}
	for (i = 0; i < n; i++)
		printf("%d\n", arr[i]);
	return 0;
}